package com.ishang.vm.service;

import com.ishang.vm.dao.PartyMemberDAO;
import com.ishang.vm.pojo.PartyMember;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PartyMemberService {
    @Autowired
    PartyMemberDAO partyMemberDAO;

    public List<PartyMember> list() {
        Sort sort = new Sort(Sort.Direction.DESC, "id");
        return partyMemberDAO.findAll(sort);
    }

    public boolean addOrUpdate(PartyMember partyMember) {
        try {
            partyMemberDAO.save(partyMember);
        } catch (IllegalArgumentException e) {
            return false;
        }
        return true;
    }

    public boolean deleteById(int id) {
        try {
            partyMemberDAO.deleteById(id);
        } catch (IllegalArgumentException e) {
            return false;
        }
        return true;
    }

    public List<PartyMember> Search(String keywords) {
        return partyMemberDAO.findByNameOrIdnumOrPhone('%' + keywords + '%', '%' + keywords + '%', '%' + keywords + '%');
    }

}
